package com.nectech.util;


import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author 浅小北
 * @ClassName ImageUtil
 * @Description 图片加载类
 * @Date 2021/1/27 10:23
 * @Since version-1.0
 */

public class ImageUtil {
    private ImageUtil(){}

    /**
     * 静态加载图片，减少运行负担
     */
    private static Map<String,Image> imagesMap = new HashMap();
    static {
        //logo图片加载
        imagesMap.put("logo",GameUtil.getImage("icon/logo"));
        //英雄左边站立
        for (int i = 0; i < 4; i++) {
            imagesMap.put("hero_left_stand_" + i,GameUtil.getImage("hero/left/stand/stand1_" + i));
        }
        //英雄右边站立
        for (int i = 0; i < 4; i++) {
            imagesMap.put("hero_right_stand_" + i,GameUtil.getImage("hero/right/stand/stand1_" + i));
        }
        //英雄左边走
        for (int i = 0; i < 5; i++) {
            imagesMap.put("hero_left_walk_" + i,GameUtil.getImage("hero/left/walk/walk1_" + i));
        }
        //英雄右边走
        for (int i = 0; i < 5; i++) {
            imagesMap.put("hero_right_walk_" + i,GameUtil.getImage("hero/right/walk/walk1_" + i));
        }
        //英雄左边趴
        imagesMap.put("hero_left_prone",GameUtil.getImage("hero/left/prone/prone_0"));
        //英雄右边趴
        imagesMap.put("hero_right_prone",GameUtil.getImage("hero/right/prone/prone_0"));
        //英雄左边跳
        imagesMap.put("hero_left_jump",GameUtil.getImage("hero/left/jump/jump_0"));
        //英雄右边跳
        imagesMap.put("hero_right_jump",GameUtil.getImage("hero/right/jump/jump_0"));
        //英雄左边射箭
        for (int i = 0; i < 4; i++) {
            imagesMap.put("hero_left_shoot_" + i,GameUtil.getImage("hero/left/shoot/shoot1_" + i));
        }
        //英雄右边射箭
        for (int i = 0; i < 4; i++) {
            imagesMap.put("hero_right_shoot_" + i,GameUtil.getImage("hero/right/shoot/shoot1_" + i));
        }
        //左边的箭矢
        imagesMap.put("hero_left_arrow",GameUtil.getImage("hero/left/arrow/arrow"));
        //右边的箭矢
        imagesMap.put("hero_right_arrow",GameUtil.getImage("hero/right/arrow/arrow"));
        //左边怪物站立
        for (int i = 0; i < 3; i++) {
            imagesMap.put("mob_left_stand_" + i,GameUtil.getImage("mob/left/stand/stand_" + i));
        }
        //右边怪物怪物站立
        for (int i = 0; i < 3; i++) {
            imagesMap.put("mob_right_stand_" + i,GameUtil.getImage("mob/right/stand/stand_" + i));
        }
        //左边怪物移动
        for (int i = 0; i < 4; i++) {
            imagesMap.put("mob_left_move_" + i,GameUtil.getImage("mob/left/move/move_" + i));
        }
        //右边怪物移动
        for (int i = 0; i < 4; i++) {
            imagesMap.put("mob_right_move_" + i,GameUtil.getImage("mob/right/move/move_" + i));
        }
        //左边怪物受击
        imagesMap.put("mob_left_hit",GameUtil.getImage("mob/left/hit/hit1_0"));
        //右边怪物受击
        imagesMap.put("mob_right_hit",GameUtil.getImage("mob/right/hit/hit1_0"));
        //左边怪物死亡
        for (int i = 0; i < 4; i++) {
            imagesMap.put("mob_left_die_" + i,GameUtil.getImage("mob/left/die/die1_" + i));
        }
        //右边怪物死亡
        for (int i = 0; i < 4; i++) {
            imagesMap.put("mob_right_die_" + i,GameUtil.getImage("mob/right/die/die1_" + i));
        }
        //怪物攻击
        for (int i = 0; i < 9; i++) {
            imagesMap.put("mob_attack_" + i,GameUtil.getImage("mob/attack/attack" + i));
        }
        //血条图片
        imagesMap.put("mob_blood",GameUtil.getImage("blood/blood"));
        //道具图片
        imagesMap.put("hp_50",GameUtil.getImage("prop/hp_50"));
        imagesMap.put("hp_100",GameUtil.getImage("prop/hp_100"));
        imagesMap.put("hp_300",GameUtil.getImage("prop/hp_300"));
        imagesMap.put("mp_100",GameUtil.getImage("prop/mp_100"));
        //道具包图片
        imagesMap.put("propPackage",GameUtil.getImage("propPackage/propPackage"));
        //伤害数字图片
        for (int i = 0; i < 10; i++) {
            imagesMap.put("power_" + i,GameUtil.getImage("power/" + i));
        }
        //人物血条
        imagesMap.put("person_blood",GameUtil.getImage("person/bloodblock/blood"));
        //人物蓝条
        imagesMap.put("person_bluemp",GameUtil.getImage("person/bluemp/bluemp"));
        //人物经验条
        imagesMap.put("person_purpleexp",GameUtil.getImage("person/purpleexp/purpleexp"));
        //人物爬行图片
        imagesMap.put("hero_climb",GameUtil.getImage("hero/climb/climb"));
    }

     /**
      * @Author: 浅小北
      * @Description: 获取图片对象
      * @Date: 18:18 2021/1/27
      * @Param: k键值
      * @return: Image图片对象
      */
     public static Image getImage(String imgName) {
         return imagesMap.get(imgName);
     }

}
